package com.example.mylibrary;

        import static android.content.ContentValues.TAG;
        import android.app.Instrumentation;
        import android.util.Log;
        import androidx.test.platform.app.InstrumentationRegistry;
        import androidx.test.uiautomator.By;
        import androidx.test.uiautomator.UiDevice;
        import androidx.test.uiautomator.UiObject2;

        import org.junit.After;
        import org.junit.Before;
        import org.junit.Test;

public class BarterCollectionPage {
    public static UiDevice device;
    public static Instrumentation instrumentation;

    @Before
    public void first() throws InterruptedException{
        Log.i(TAG,"连接设备");
        instrumentation=
                InstrumentationRegistry.getInstrumentation();
        device= UiDevice.getInstance(instrumentation);
        int width = device.getDisplayWidth();
        int height = device.getDisplayHeight();
        device.pressHome();
        Thread.sleep(2000);
        device.swipe(width-10,height/2,50,height/2,10);
        Thread.sleep(2000);
        UiObject2 barter = device.findObject(By.text("Barter"));
        barter.click();
        Thread.sleep(3000);
    }

    //    登录
    private void login() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).setText("2019012514");
        Thread.sleep(100);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_login")).click();
        Thread.sleep(1000);
    }

    //    收藏商品
    @Test
    public void testMyLove() throws InterruptedException {
        login();
        Thread.sleep(1000);
        device.click(200,700);
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/ib_my_love")).click();
        Thread.sleep(1000);

    }

    //    添加评论
    @Test
    public void testAddCommends() throws InterruptedException {
        login();
        Thread.sleep(1000);
        device.click(200,700);
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_comment")).setText("看起来不错呦");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_comment")).setText("看起来不错呦");
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_submit")).click();

    }

    @After
    public static void tearDown() {
        device.pressBack();
    }
}
